package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.Book;
import com.example.demo.entity.dto.TopBorrowedBook;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TopBorrowedBookMapper extends BaseMapper<Book> {
    @Select("SELECT book_name AS name , COUNT(*) AS borrow_count " +
            "FROM borrow " +
            "WHERE YEAR(borrow_date) = YEAR(CURRENT_DATE()) " +
            "AND MONTH(borrow_date) = (MONTH(CURRENT_DATE())-1) " +
            "GROUP BY name " +
            "ORDER BY borrow_count DESC " +
            "LIMIT 5")
    List<TopBorrowedBook> getTopBorrowedBooks();
}
